#============================================================
#	Mouse Create Item
#============================================================
#  点击创建物品
#============================================================
# @datetime: 2022-5-3 18:24:34
#============================================================
class_name ClickCreateItem
extends Node



func _unhandled_input(event):
	# 右键点击创建物品
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_RIGHT and event.pressed:
			var scene = get_tree().current_scene 
			if scene is Node2D:
				create_item(scene.get_global_mouse_position())


func create_item(position: Vector2):
	Logger.info(self, ['点击位置：', position])
	var node = ItemFactory.rand_item_node()
	get_tree().current_scene.call_deferred("add_child", node)
	node.global_position = position

